$(document).ready(function() {
    $(".xf_sum").keyup(function() {
        var saving_sub = $("#saving_sub").val();
        var cash = $("#cash").val();
        var point_sub = $("#point_sub").val();
        var sum = Number(saving_sub)+Number(cash)+Number(point_sub);
        $("#xf_sum").text(sum);
        
    }).bind("paste", function() {
       
    });

	$(".bnt_frm").click(function() {
		var cardno = $("#cardno").val();
        var passwd = $("#passwd").val();
        if (cardno =="") {
        	jAlert("请填写卡号","支付失败","");
        	return false;
        }
		$.ajax({
            url: "index.php?go=softpos.api.ajaxKzf",
            type: 'post',
            dataType: 'json',
            data:$("#frm").serialize(),
            success: function(response) {
                if (response.success == "success") {
                    jAlert("支付成功","支付成功",function(r) {
                        if (r==true) {
                            var myDate = new Date();
                            var ymd = myDate.toLocaleDateString(); 
                            var mytime=myDate.toLocaleTimeString();
                            $("#date_show").html(ymd);
                            $("#time_show").html(mytime);
                            var data = response.data;
                            $("#batch_show").html(data.batch);
                            $("#traceon_show").html(data.trace_no);
                            $("#invoiceid_show").html(data.invoice_id);
                            $("#sum_show").html(data.total);
                            if (data.coupon_amount==null) {data.coupon_amount="0";};
                            $("#coupon_show").html(data.coupon_amount);
                            var member = response.member;
                            $("#balance_show").html(member.user_balance);
                            $("#point_show").html(member.user_point);

                            var saving_sub =$("#saving_sub").val();
                            $("#saving_sub_show").html(saving_sub);
                            var cash =$("#cash").val();
                            $("#cash_show").html(cash);
                            var point_sub =$("#point_sub").val();
                            $("#point_sub_show").html(point_sub);
                            

                            $(".shadow").show();
                            $("#hidden_form").show();
                        }
                    });
                } else {
                    jAlert(response.data,"支付失败","");
                }
            }
        });
	});
    $(".hidden_form_top_r").click(function(){
        location.reload();
        $(".shadow").hide();
        $("#hidden_form").hide();
    })
    $(".sendSms").click(function(){
        var contents = "卡号："+$("#cardno").val()+" 本次消费金额："+$("#sum_show").text()+"元(现金支付："+$("#cash_show").text()+"元，储值支付："+$("#saving_sub_show").text()+"元，积分支付："+$("#point_sub_show").text()+"，券支付："+$("#coupon_show").text()+"元)";
        var user_mobile =$("#user_mobile").val();
        var data = {mobile:user_mobile,contents:contents};
        $.ajax({
            url: "index.php?go=softpos.api.sendSms",
            type: 'post',
            dataType: 'json',
            data:data,
            success: function(response) {
                if (response.success == "success") {
                    jAlert("发送成功","发送成功",function(r) {
                        if (r==true) {
                           location.reload(); 
                        }
                    });
                } else {
                    jAlert(response.data,"发送失败","");
                }
            }
        });
    });
    // $(".sendwx").click(function(){
    //     var contents = "卡号："+$("#cardno").val()+" 本次消费："+$("#sum_show").text();
    //     var user_mobile =$("#user_mobile").val();
    //     var data = {mobile:user_mobile,contents:contents};
    //     $.ajax({
    //         url: "index.php?go=softpos.api.sendwx",
    //         type: 'post',
    //         dataType: 'json',
    //         data:data,
    //         success: function(response) {
    //             if (response.success == "success") {
    //                 jAlert("发送成功","发送成功",function(r) {
    //                     if (r==true) {
    //                        location.reload(); 
    //                     }
    //                 });
    //             } else {
    //                 jAlert(response.data,"发送失败","");
    //             }
    //         }
    //     });
    // });
});